// pages/order/balance/balance.js
const app = getApp()
Page({
  data: {
    activity:false,
    discount:false,
    full:0,
    decrease:0,
    sumMoney : 0,
    note:'', //备注信息 
    taken:false, //是否取餐
    carList: [] 
  },
  choose1:function(){
    this.setData({
      taken: false
    })
  },
  choose2:function(){
    this.setData({
      taken: true
    })
  },
  gotolist:function(){
    var pay = {
      order:[
      ]
    };
    pay.order = this.data.carList;
    app.globalData.payList.push(pay);
    wx.switchTab({
      url: '../list/list',
    })
    // wx.navigateTo({
    //   url: '../list/list',
    // })
  },
  onLoad:function(options){
    var that = this;
    wx.request({
      url: 'http://localhost:8080/activity/all',
      success:function(res){
        if(res.data.list!=null){
          var i = res.data.list.length-1;
          console.log(res.data.list[i].full),
          console.log(res.data.list[i].decrease),
          that.setData({
            full:res.data.list[i].full,
            decrease:res.data.list[i].decrease,
            activity:true
          })
        }
        that.setData({
          carList : app.globalData.carList
        })
        var sum =0;
        for(var i in that.data.carList){
            sum+=that.data.carList[i].price * that.data.carList[i].number;
        }
        console.log(sum);
        if(sum>=that.data.full){
          that.setData({
            discount:true,
            sumMoney:sum-that.data.decrease
          })
        }else{
          that.setData({
            sumMoney:sum
          })
        }
      }
    })
    
    // temp = sum - this.data.full;
    // if(temp<0){
    //   temp=0;
    // }else{
    //   temp=this.data.decrease;
    // }
    // this.setData({
    //     sumMoney:sum-temp
    // })
  }
})